using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Text;
using SystemFrameworks;
using Common;
using Microsoft.ApplicationBlocks;
using BusinessRules;
using DataAccess;
using Microsoft.ApplicationBlocks.Data;

namespace BusinessRules
{
    public class DocumentosEpes
    {
        #region Params

        private const String FED_ID_PARAM = "@FED_ID";
        private const String FAE_ID_PARAM = "@FAE_ID";
        private const String FED_RESPONSABLE_PARAM = "@FED_RESPONSABLE";
        private const String FED_VALOR_PARAM = "@FED_VALOR";
        
        #endregion

        #region Propiedades

        private string _CadenaConexion;

        public string CadenaConexion
        {
            get { return _CadenaConexion; }
            set { _CadenaConexion = value; }
        }

        #endregion

        #region DocumentosEpes

        public DocumentosEpes(string strCadenaConecxion)
        {
            CadenaConexion = strCadenaConecxion;
        }

        #endregion

        //#region BuscarNivel1

        //public BasPlanDecenalData BuscarNivel1()
        //{
        //    BasPlanDecenalData objBasPlanDecenalData = new BasPlanDecenalData();
        //    SqlHelper.ExecuteDataTable(CadenaConexion, CommandType.StoredProcedure, "PAS_BUSCAR_BAS_PLAN_DECENAL", objBasPlanDecenalData);
        //    return objBasPlanDecenalData;
        //}

        //#endregion

        #region ConsultarDocumentosEpes

        public FinDocumentosEpesData ConsultarDocumentosEpes(string strFaeId)
        {
            FinDocumentosEpesData objFinDocumentosEpesData = new FinDocumentosEpesData();
            SqlParameter param1 = new SqlParameter(FAE_ID_PARAM, strFaeId);
            SqlParameter[] parameters = { param1 };
            SqlHelper.ExecuteDataTable(CadenaConexion, CommandType.StoredProcedure, "PAS_CONSULTAR_FIN_DOCUMENTOS_EPES_FAE_ID", objFinDocumentosEpesData, parameters);
            return objFinDocumentosEpesData;
        }

        #endregion


        #region AdicionarDocumentosEpes

        public void AdicionarDocumentosEpes(FinDocumentosEpesData objDT, params SqlTransaction[] objTransaction)
        {
            try
            {
                foreach (DataRow objRow in objDT.Rows)
                {
                    SqlParameter param1 = new SqlParameter(FED_ID_PARAM, objRow[FinDocumentosEpesData.FED_ID_FIELD]);
                    SqlParameter param2 = new SqlParameter(FAE_ID_PARAM, objRow[FinDocumentosEpesData.FAE_ID_FIELD]);
                    SqlParameter param3 = new SqlParameter(FED_RESPONSABLE_PARAM, objRow[FinDocumentosEpesData.FED_RESPONSABLE_FIELD]);
                    SqlParameter param4 = new SqlParameter(FED_VALOR_PARAM, objRow[FinDocumentosEpesData.FED_VALOR_FIELD]);
                    SqlParameter[] parameters = { param1, param2, param3, param4};
                    if (objTransaction.Length == 0)
                    {
                        SqlHelper.ExecuteNonQuery(CadenaConexion, CommandType.StoredProcedure,
                                                  "PAS_ADICIONAR_FIN_DOCUMENTOS_EPES", parameters);
                    }
                    else
                    {
                        SqlHelper.ExecuteNonQuery(objTransaction[0], CommandType.StoredProcedure,
                                                  "PAS_ADICIONAR_FIN_DOCUMENTOS_EPES", parameters);
                    }
                }
            }
            catch (Exception objEx)
            {
                throw new ApplicationExceptionManager(Utilidad.TraerMensaje("gmsgErrorInsertar", "PAS_ADICIONAR_FIN_DOCUMENTOS_EPES"), objEx);
            }


        }

        #endregion AdicionarPerfil


        #region ElimarDocumentosEpes

        public void ElimarDocumentosEpes(decimal decFaeId, params SqlTransaction[] objTransaction)
        {
            try
            {

                SqlParameter param1 = new SqlParameter(FAE_ID_PARAM, decFaeId);
                    SqlParameter[] parameters = { param1};
                    if (objTransaction.Length == 0)
                    {
                        SqlHelper.ExecuteNonQuery(CadenaConexion, CommandType.StoredProcedure,
                                                  "PAS_ELIMINAR_FIN_DOCUMENTOS_EPES", parameters);
                    }
                    else
                    {
                        SqlHelper.ExecuteNonQuery(objTransaction[0], CommandType.StoredProcedure,
                                                  "PAS_ELIMINAR_FIN_DOCUMENTOS_EPES", parameters);
                    }
            }
            catch (Exception objEx)
            {
                throw new ApplicationExceptionManager(Utilidad.TraerMensaje("gmsgErrorInsertar", "PAS_ADICIONAR_FIN_DOCUMENTOS_EPES"), objEx);
            }


        }

        #endregion AdicionarPerfil
    }
}
